/*
 * @Author: xiaosihan 
 * @Date: 2024-08-06 11:16:27 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-08-18 04:33:12
 */


import partsApi from "@api/partsApi";
import { get, isEmpty } from "lodash";
import { configure, observable } from "mobx";
configure({ enforceActions: "never" });

const shareModalStore = observable({

    show: false,
    setShow(show: boolean) {
        this.show = show;
    },

    shareId: "",
    shareToken: "",
    openShare: false,
    async getShareToken(modelId: string = "") {
        const res = await partsApi.getShare(modelId);
        const token = get(res, ["data", "token"]);
        const id = get(res, ["data", "id"]);
        this.shareId = id;
        this.shareToken = token;
        this.openShare = !isEmpty(token);
    },
    //关闭分享
    async closeShare(modelId: string) {
        await partsApi.deleteShare(this.shareId);
        await this.getShareToken(modelId);
    },
    //打开分享链接
    async addShare(modelId: string) {
        await partsApi.getShareToken(modelId);
        this.getShareToken(modelId);
    }


});
export default shareModalStore;